/**
 * JedisClientSingle.java 2017年7月26日 上午8:14:13
 * Copyright ©2017 wondersgroup.com All rights reserved. 
 * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package cn.easy.rest.dao.impl;

import cn.easy.rest.dao.JedisClient;
import org.springframework.beans.factory.annotation.Autowired;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * File：JedisClientSingle.java <br>
 * Title: <br>
 * Description: <br>
 * Company: wondersgroup.com <br>
 * @author zjsxx
 * @version 1.0
 */
public class JedisClientSingle implements JedisClient {
	@Autowired
	private JedisPool jedisPool;

	@Override
	public String get(String key) {
		Jedis jedis = jedisPool.getResource();
		String string = jedis.get(key);
		jedis.close();
		return string;
	}


	@Override
	public String set(String key, String value) {
		Jedis jedis = jedisPool.getResource();
		String string = jedis.set(key, value);
		jedis.close();
		return string;
	}


	@Override
	public String hget(String hkey, String key) {
		Jedis jedis = jedisPool.getResource();
		String string = jedis.hget(hkey, key);
		jedis.close();
		return string;
	}

	@Override
	public Long hset(String hkey, String key, String value) {
		Jedis jedis = jedisPool.getResource();
		Long longResult = jedis.hset(hkey, key, value);
		jedis.close();
		return longResult;
	}

	/**
	 * 值+1
	 */
	@Override
	public long incr(String key) {
		Jedis jedis = jedisPool.getResource();
		Long longResult = jedis.incr(key);
		jedis.close();
		return longResult;
		
	}
	/*
	 * 设置生存时间
	 */
	@Override
	public long expire(String key, int second) {
		Jedis jedis = jedisPool.getResource();
		Long expire = jedis.expire(key, second);
		jedis.close();
		return expire;
	}

	//查看剩余生存时间
	@Override
	public long ttl(String key) {
		Jedis jedis = jedisPool.getResource();
		Long time = jedis.ttl(key);
		jedis.close();
		return time;
	}


	
	@Override
	public long del(String key) {
		Jedis jedis = jedisPool.getResource();
		Long longResult = jedis.del(key);
		jedis.close();
		return longResult;
	}



	@Override
	public long hdel(String hkey, String key) {
		Jedis jedis = jedisPool.getResource();
		Long hdelResult = jedis.hdel(hkey, key);
		jedis.close();
		return hdelResult;
	}

	
	
}
